CSS provider: Add a way to emit errors
authorMatthias Clasen <mclasen@redhat.com>
Sat, 30 Jan 2016 03:45:21 +0000 (22:45 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 30 Jan 2016 05:29:04 +0000 (00:29 -0500)
Currently, GtkCssProvider can emit ::parsing-error only during
the actual parsing, although the documentation hints that it might
happen at other times.

This commit adds a emit_error method to the GtkStyleProviderPrivate
interface that will let us emit errors from the compute() implementations
as well, which can be useful (e.g. if an image fails to load).

gtk/gtkcssprovider.c
gtk/gtkstyleproviderprivate.c
gtk/gtkstyleproviderprivate.h

index f60a0bfa0d84a488444e6eb5fce6176b6576d963..1c192c749336ed69bf3fecacb0d961559b97686f 100644 (file)
@@ -142,6 +142,9 @@ static void gtk_css_provider_finalize (GObject *object);
 static void gtk_css_style_provider_iface_init (GtkStyleProviderIface *iface);
 static void gtk_css_style_provider_private_iface_init (GtkStyleProviderPrivateInterface *iface);
 static void widget_property_value_list_free (WidgetPropertyValue *head);
+static void gtk_css_style_provider_emit_error (GtkStyleProviderPrivate *provider,
+                                               GtkCssSection           *section,
+                                               const GError            *error);
 
 static gboolean
 gtk_css_provider_load_internal (GtkCssProvider *css_provider,
@@ -405,13 +408,22 @@ gtk_css_scanner_destroy (GtkCssScanner *scanner)
   g_slice_free (GtkCssScanner, scanner);
 }
 
+static void
+gtk_css_style_provider_emit_error (GtkStyleProviderPrivate *provider,
+                                   GtkCssSection           *section,
+                                   const GError            *error)
+{
+  g_signal_emit (provider, css_provider_signals[PARSING_ERROR], 0, section, error);
+}
+
 static void
 gtk_css_provider_emit_error (GtkCssProvider *provider,
                              GtkCssScanner  *scanner,
                              const GError   *error)
 {
-  g_signal_emit (provider, css_provider_signals[PARSING_ERROR], 0,
-                 scanner != NULL ? scanner->section : NULL, error);
+  gtk_css_style_provider_emit_error (GTK_STYLE_PROVIDER_PRIVATE (provider),
+                                     scanner ? scanner->section : NULL,
+                                     error);
 }
 
 static void
@@ -421,9 +433,7 @@ gtk_css_scanner_parser_error (GtkCssParser *parser,
 {
   GtkCssScanner *scanner = user_data;
 
-  gtk_css_provider_emit_error (scanner->provider,
-                               scanner,
-                               error);
+  gtk_css_provider_emit_error (scanner->provider, scanner, error);
 }
 
 static GtkCssScanner *
@@ -785,6 +795,7 @@ gtk_css_style_provider_private_iface_init (GtkStyleProviderPrivateInterface *ifa
   iface->get_color = gtk_css_style_provider_get_color;
   iface->get_keyframes = gtk_css_style_provider_get_keyframes;
   iface->lookup = gtk_css_style_provider_lookup;
+  iface->emit_error = gtk_css_style_provider_emit_error;
 }
 
 static void
@@ -834,10 +845,7 @@ gtk_css_provider_take_error (GtkCssProvider *provider,
                              GtkCssScanner  *scanner,
                              GError         *error)
 {
-  gtk_css_provider_emit_error (provider,
-                               scanner,
-                               error);
-
+  gtk_css_provider_emit_error (provider, scanner, error);
   g_error_free (error);
 }
 
index dbf6e3cbc20507d80eb65d7d7368cf9a6cbab132..8779f1e57d29d2c1b0cda399bcbfaff2ecaeef51 100644 (file)
@@ -142,3 +142,16 @@ _gtk_style_provider_private_get_scale (GtkStyleProviderPrivate *provider)
 
   return iface->get_scale (provider);
 }
+
+void
+_gtk_style_provider_private_emit_error (GtkStyleProviderPrivate *provider,
+                                        GtkCssSection           *section,
+                                        GError                  *error)
+{
+  GtkStyleProviderPrivateInterface *iface;
+
+  iface = GTK_STYLE_PROVIDER_PRIVATE_GET_INTERFACE (provider);
+
+  if (iface->emit_error)
+    iface->emit_error (provider, section, error);
+}
index ff58b9e869a5b8f0672c01765be1258140d8ec08..086119c7e828e2a0e6c5881710191ffb95d2f5cf 100644 (file)
@@ -49,7 +49,9 @@ struct _GtkStyleProviderPrivateInterface
                                                  const GtkCssMatcher     *matcher,
                                                  GtkCssLookup            *lookup,
                                                  GtkCssChange            *out_change);
-
+  void                  (* emit_error)          (GtkStyleProviderPrivate *provider,
+                                                 GtkCssSection           *section,
+                                                 const GError            *error);
   /* signal */
   void                  (* changed)             (GtkStyleProviderPrivate *provider);
 };
@@ -69,6 +71,10 @@ void                    _gtk_style_provider_private_lookup       (GtkStyleProvid
 
 void                    _gtk_style_provider_private_changed      (GtkStyleProviderPrivate *provider);
 
+void                    _gtk_style_provider_private_emit_error   (GtkStyleProviderPrivate *provider,
+                                                                  GtkCssSection           *section,
+                                                                  GError                  *error);
+
 G_END_DECLS
 
 #endif /* __GTK_STYLE_PROVIDER_PRIVATE_H__ */